package br.edu.udc.JMonster.view.dto
{
	import com.adobe.cairngorm.vo.IValueObject;
	
	import mx.formatters.CurrencyFormatter;
	import mx.formatters.DateFormatter;
	
	/**
	 * 2008 - ApolloTi Desenvolvimento de Software LTDA. 
	 * Todos os direitos reservados.
	 * 
	 * @author Rodrigo P. Fraga
	 * @email rodrigo@apollo-ti.com
	 * @since 20/02/2008
	 * @version 1.0
	 * @category EntityPowerType
	 */
	[Bindable]
	[RemoteClass(alias="br.edu.udc.JMonster.business.DataTransferObject.AbstractPersistentObject")]
	public class AbstractPersistentObject implements IValueObject
	{
		/*-------------------------------------------------------------------
	 	* 		 					ATTRIBUTES
	 	*-------------------------------------------------------------------*/
		private var _id:int;
		private var _dtCadastro:Date;
		private var _dtAlteracao:Date;
		
		protected var dtFormatter:DateFormatter;
		protected var numberToReal:CurrencyFormatter;
		protected var realToNumber:CurrencyFormatter;		
		protected var currencyFormatter:CurrencyFormatter;
		
		/*-------------------------------------------------------------------
	 	*				 		    CONSTRUCTOR
	 	*-------------------------------------------------------------------*/
		public function AbstractPersistentObject():void
		{
			this.dtFormatter = new DateFormatter();
			this.dtFormatter.formatString = "DD/MM/YYYY";//- JJ:NN:SS";
			
			this.numberToReal = new CurrencyFormatter();
			this.numberToReal.currencySymbol = "";
			this.numberToReal.alignSymbol = "left";
			this.numberToReal.precision = 2;
			this.numberToReal.decimalSeparatorFrom = ".";
			this.numberToReal.decimalSeparatorTo = ",";
			this.numberToReal.thousandsSeparatorFrom = ",";
			this.numberToReal.thousandsSeparatorTo = ".";
			
			this.realToNumber = new CurrencyFormatter();
			this.realToNumber.currencySymbol = "";
			this.realToNumber.alignSymbol = "left";
			this.realToNumber.useThousandsSeparator = false;
			this.realToNumber.decimalSeparatorFrom = ",";
			this.realToNumber.decimalSeparatorTo = ".";
			this.realToNumber.thousandsSeparatorFrom = ".";
			this.realToNumber.thousandsSeparatorTo = ",";
			
			this.currencyFormatter = new CurrencyFormatter();
			this.currencyFormatter.currencySymbol = "R$";
			this.currencyFormatter.alignSymbol = "left";
			this.currencyFormatter.useThousandsSeparator = true;
			this.currencyFormatter.precision = 2;
			this.currencyFormatter.decimalSeparatorFrom = ".";
			this.currencyFormatter.decimalSeparatorTo = ",";
			this.currencyFormatter.thousandsSeparatorFrom = ",";
			this.currencyFormatter.thousandsSeparatorTo = ".";
		}
		
		/*-------------------------------------------------------------------
	 	* 		 					DECORATORS
	 	*-------------------------------------------------------------------*/
		public function get dtCadastroFormatada():String
		{
			return dtFormatter.format(_dtCadastro);
		}
		public function set dtCadastroFormatada(value:String):void
		{
			throw new Error("Não é possível inserir uma dada de cadastro formatada.");
		}
				
		public function get dtAlteracaoFormatada():String
		{
			return dtFormatter.format(_dtAlteracao);
		}
		public function set dtAlteracaoFormatada(value:String):void
		{
			throw new Error("Não é possível inserir uma dada de alteração formatada.");
		}
		
		/*-------------------------------------------------------------------
	 	*				 		GET'S AND SET'S
	 	*-------------------------------------------------------------------*/		
		public function set dtCadastro(value:Object):void
		{
			this._dtCadastro = new Date(value);
		}
		public function get dtCadastro():Object
		{
			return this._dtCadastro;
		}
		
		public function set dtAlteracao(value:Object):void
		{
			this._dtAlteracao = new Date(value);
		}
		public function get dtAlteracao():Object
		{
			return this._dtAlteracao;	
		}

		public function set id(value:int):void
		{
			_id = value;
		}
		public function get id():int
		{
			return _id;
		}
	}
}